#!/usr/bin/python3
# -*-coding:utf-8 -*-

# Reference:**********************************************
# @Time    : 12/16/2019 6:16 PM
# @Author  : Gaopeng.Bai
# @File    : Preprocessing_cifar10.py
# @User    : baigaopeng
# @Software: PyCharm
# Reference:**********************************************
from keras.datasets import cifar10
from keras.utils import np_utils
import numpy as np


class preprecessiong:
    def __init__(self, args):
        self.pixel_normalized = 128.
        self.args = args


    def cifar10(self):
        # The data, shuffled and split between train and test sets:
        (X_train, y_train), (X_test, y_test) = cifar10.load_data()

        # Convert class vectors to binary class matrices.
        Y_train = np_utils.to_categorical(y_train,self.args.nb_classes)
        Y_test = np_utils.to_categorical(y_test, self.args.nb_classes)

        X_train = X_train.astype('float32')
        X_test = X_test.astype('float32')

        # subtract mean and normalize
        mean_image = np.mean(X_train, axis=0)
        X_train -= mean_image
        X_test -= mean_image
        X_train /= self.pixel_normalized
        X_test /= self.pixel_normalized

        return X_train, Y_train, X_test, Y_test


if __name__ == '__main__':
    pre = preprecessiong(args=10)
    X_train, Y_train, X_test, Y_test = pre.cifar10()
